package com.geek.concurrence4work;

import java.util.concurrent.*;

/**
 * @Author: lishuangqiang
 * @Date: 2021/11/28
 * @Description:
 */

public class CompletionServiceMethod {

    public static class MyCallable implements Callable<Long> {

        @Override
        public Long call() throws Exception {
            return Homework03.sum3();
        }
    }


    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyCallable myCallable = new MyCallable();
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 1, 2, TimeUnit.SECONDS, new LinkedBlockingDeque<>());
        CompletionService completionService = new ExecutorCompletionService(threadPoolExecutor);
        Object res = completionService.submit(myCallable).get();
        System.out.println(res);
    }


}
